//
//  SaveCorrectionResultViewController.m
//  AI
//
//  Created by zjhc on 2018/2/6.
//  Copyright © 2018年 zjhc. All rights reserved.
//  Description:音频文本矫正

#import "SaveCorrectionResultViewController.h"
#import "AudioListModel.h"
#import "AFAppDotNetAPIClient.h"
#import "UrlManage.h"
#import <SVProgressHUD.h>


@interface SaveCorrectionResultViewController ()

@end

@implementation SaveCorrectionResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.saveCorrectionTextView.text = self.record.content;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark - 保存校对文本事件
- (IBAction)saveCorrectionAction:(id)sender {
    self.record.update_content=self.saveCorrectionTextView.text;
    [self audioTextCorrectionService:self.saveCorrectionTextView.text];
    
}

#pragma mark - 音频文本校对接口服务
- (void)audioTextCorrectionService:(NSString *)text {
    
    if (self.record.content == nil) {
        self.record.content = @"";
    }
    
    NSDictionary * mutableDic = @{@"content":self.record.content,@"updateContent":text,@"id":[NSNumber numberWithInteger:self.record.rid]};
    
    NSString *urlString = [NSString stringWithFormat:@"%@?access_token=%@",[UrlManage sharedManager].audioUpdate,[NSUserDefaultsUtil gettoken]];
    [AFAppDotNetAPIClient postAsynchronous:urlString parameter:mutableDic successBlock:^(NSDictionary *result, NSError *error) {
        
        if ([[result objectForKey:@"code"] isEqualToString:@"0"]) {
            [self performSegueWithIdentifier:@"unwindToErrorCorrectionVC" sender:nil];
            [SVProgressHUD showErrorWithStatus:@"矫正成功"];

        } else {
            [SVProgressHUD showErrorWithStatus:[result objectForKey:@"msg"]];
        }
        
    } errorBlock:^(NSError *error) {
        
      
        
    }];
    
}

-(void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}
@end
